<!-- 冷热源 》 冷源系统 -->

<template>
  <el-card
    class="source-cold"
    shadow="never"
    body-style="display: flex; flex-direction: column; height: calc(100% - 20px); padding: 10px 15px;"
  >
    <SourceColdBrands class="source-cold__top-brands" />
    <div class="source-cold__canvas-wrapper">
      <ModelFrame path="/source/cold" />
    </div>

    <EasyModal v-model="waterCoolerDetailsDialogIsShow" title="设备详情" :width="800" :no-footer="true">
      <WaterCoolerDetails />
    </EasyModal>
    <EasyModal v-model="coolingTowerDetailsDialogIsShow" title="设备详情" :width="800" :no-footer="true">
      <CoolingTowerDetails />
    </EasyModal>
  </el-card>
</template>

<script>
// ============================== 导入依赖 ============================== //

import CORE from '@/CORE'
import SourceColdBrands from './components/brands/index.vue'
import WaterCoolerDetails from './components/water-cooler-details/index.vue'
import CoolingTowerDetails from './components/cooling-tower-details/index.vue'

// ============================== 导出组件 ============================== //

export default {
  /**
   * 名称定义 (实际使用名称)
   */
  name: 'SourceCold',

  data() {
    return {
      /**
       * 冷水机详情对话框是否显示
       */
      waterCoolerDetailsDialogIsShow: false,
      /**
       * 冷却塔详情对话框是否显示
       */
      coolingTowerDetailsDialogIsShow: false,
    }
  },

  components: {
    SourceColdBrands,
    WaterCoolerDetails,
    CoolingTowerDetails,
  },

  /**
   * 挂载完成 (先抽取再调用)
   */
  mounted() {
    window.addEventListener('message', this.onMessage)
  },

  /**
   * 销毁之前 (先抽取再调用)
   */
  beforeDestroy() {
    window.removeEventListener('message', this.onMessage)
  },

  /**
   * 本地方法 (轻量重要在前)
   */
  methods: {
    /**
     * 收到消息
     */
    onMessage(event) {
      if (process.env.VUE_APP_DEBUG_PORT || event.origin === location.origin) { // 调试环境，或是同源消息
        if (CORE.isBoolean(this[event.data])) {
          CORE.logInfo('子页面消息', {}, event)
          this[event.data] = true
        }
      }
    },
  },
}
</script>

<style lang="scss" scope>
@import './index.scss';
</style>
